package com.middlegroup.subjectpay.entity;

import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableName;
import com.middlegroup.common.enums.AesKeyUtil;
import com.middlegroup.common.mybatisplus.BaseEntity;
import com.middlegroup.common.utils.AesUtils;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

/**
 * <p>
 * 协议支付申请记录表（针对首次支付成功就是绑卡成功的协议支付）
 * </p>
 *
 * @author chengweiwei123
 * @since 2019-01-28
 */
@TableName("t_third_protocol_apply")
@Data
public class ThirdProtocolApply extends BaseEntity {

    private static final long serialVersionUID = 1L;

    @TableField("subject_code")
    private String subjectCode;
    @TableField("channel_code")
    private String channelCode;
    /**
     * 签约商户订单号
     */
    @TableField("merchant_bill_no")
    private String merchantBillNo;
    /**
     * 我方提交上游订单号
     */
    @TableField("bill_no")
    private String billNo;
    /**
     * 签约卡号
     */
    @TableField("card_no")
    private String cardNo;
    /**
     * 银行预留手机号，密文
     */
    private String phone;
    /**
     * 姓名，密文
     */
    private String name;
    /**
     * 身份证号，密文
     */
    @TableField("id_card")
    private String idCard;
    /**
     * 0:待签约，1：成功，2：失败
     */
    private Integer status;
    /**
     * 通道返回的校验码(如果有)
     */
    @TableField("valid_code")
    private String validCode;


    /**
     * 解密
     *
     * @throws Exception
     */
    public void GetDecryptAll(String askey) throws Exception {
        this.cardNo = AesUtils.decrypt(cardNo, askey);
        this.idCard = AesUtils.decrypt(idCard, askey);
        this.name = AesUtils.decrypt(name, askey);
        this.phone = AesUtils.decrypt(phone, askey);
    }

    /**
     * 加密
     *
     * @param aeskey
     * @throws Exception
     */
    public void SetEncryptAll(String aeskey) throws Exception {
        if (StringUtils.isNotBlank(cardNo)) {
            this.cardNo = AesUtils.encrypt(cardNo, aeskey);
        }
        if (StringUtils.isNotBlank(idCard)) {
            this.idCard = AesUtils.encrypt(idCard, aeskey);
        }
        if (StringUtils.isNotBlank(name)) {
            this.name = AesUtils.encrypt(name, aeskey);
        }
        if (StringUtils.isNotBlank(phone)) {
            this.phone = AesUtils.encrypt(phone, aeskey);
        }
    }
}
